import numpy as np
from numpy import linalg as LA
#import matplotlib.cm as cm
#import matplotlib.mlab as mlab
#import matplotlib.pyplot as plt
#
#delta = 0.025
#x = y = np.arange(-3.0, 3.0, delta)
#x2 = x ** 2
#X, Y = np.meshgrid(x, y)
#Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
#Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
#Z = Z2 - Z1  # difference of Gaussians
#
#im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray,
#                origin='lower', extent=[-3, 3, -3, 3])

#plt.show()



#import matplotlib.pyplot as plt
#import numpy as np
#
#N = 128
#x = np.arange(-5, 5, 10. / (2 * N))
#y = np.exp(-x * x * 10)
#y_fft = np.fft.fftshift(np.abs(np.fft.fft(y))) / np.sqrt(2 * N)
#plt.plot(x, y)
#plt.plot(x, y_fft)
#plt.show()


# Draw samples from the distribution:

#import numpy as np
#a = np.array([[1, 100], [1000, 10000]])
#s = np.random.poisson(a)
#
## Display histogram of the sample:
#
#import matplotlib.pyplot as plt                        #
#f = plt.figure()
#plt.plot([1, 2, 3], [1, 2, 3], 'r+', label='line 1', linewidth=2)
#plt.plot([1, 2, 3], [1, 4, 9], 'b+', label='line 2')
#plt.axis([0, 4, 0, 10])
#plt.legend()
##plt.show()
#plt.savefig('blbla200.png', dpi=(200))
#plt.savefig('blbla300.png', dpi=(300))
#plt.savefig('blbla400.png', dpi=(400))



subpix_maxdisp = 0.3
H = np.array([[1., 1.], [0, 1.]])
Hinv = LA.inv(H)
e, v = LA.eig(Hinv)
grad_L = np.array([[2.], [3.]])
p0 = -.5 * np.dot(Hinv, grad_L)
print p0
print p0.T
length_p0 = np.sqrt(np.dot(p0.T, p0))
print length_p0.item()

p0 = -subpix_maxdisp * grad_L / np.sqrt(np.dot(grad_L.T, grad_L).item())

print p0
